<?php
declare(strict_types=1);

namespace App\Resource\Web;

use App\Model\UserProfile;
use Hyperf\Resource\Json\JsonResource;
use function FastRoute\TestFixtures\empty_options_cached;

class UserProfileResource extends JsonResource
{

    public function toArray(): array
    {
        return [
            'user' => $this->getUser(),
            'profiles' => $this->getProfile(),
        ];
    }

    private function getUser(): array
    {
        $user = $this->user;
        if (empty($user)) {
            return [];
        }
        return [
            'id' => $this->id,
            'name' => $this->name,
            'avatar' => $this->avatar,
            'email' => $this->email,
        ];
    }

    private function getProfile(): array
    {
        $profile = $this->profile;
        if (empty($profile)) {
            return [];
        }
        return [
            'website' => $this->profile->website ?? '',
            'bio' => $this->profile->bio ?? '',
            'location' => $this->profile->location ?? '',
            'company' => $this->profile->company ?? '',
        ];
    }

}